<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入一个数字">
<input type="button" value="平方" onclick="square()">
<div>结果:</div>
<script>
    function square(){
        let i=document.querySelector("input");
        let d=document.querySelector("div");
        /*如果不是一个数字,则提示错误*/
        if (isNaN(i.value)){
            d.innerText="输入数据类型错误";
            return;/*中止程序,不再往下执行*/
        }
        d.innerText="结果:"+i.value*i.value;
    }
</script>
</body>
</html>